package com.czl.module_notice.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.data.bean.NoticeListBean
import com.czl.module_notice.R
import com.czl.module_notice.databinding.ItemNoticeMsgBinding
import com.czl.module_notice.fragment.NoticeListFragment

/**
 *
 * @Description:
 * @Author: XCH
 * @CreateDate: 2021/12/10 11:38
 */
class NoticeMsgAdapter(private val fragment: NoticeListFragment) :
    BaseQuickAdapter<NoticeListBean.Data, BaseDataBindingHolder<ItemNoticeMsgBinding>>(
        R.layout.item_notice_msg
    ) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemNoticeMsgBinding>,
        item: NoticeListBean.Data
    ) {
        holder.dataBinding?.apply {
            data = item
            adapter = this@NoticeMsgAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is NoticeListBean.Data) {
            fragment.viewModel.readNotice(it)
        }
    })

}
